<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">基础配置</a>
        <a href="#">添加学年页面</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div style="height: 30px"></div>
<div style="width: 500px;font-size: 10px">
    <form class="layui-form" action="" onsubmit="return false" id = 'add'>
        <div class="layui-form-item">
            <label class="layui-form-label">学年</label>
            <div class="layui-input-block">
                <input type="text" name="year" id="year"  placeholder="学年" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上学期</label>
            <div class="layui-input-block">
                <input type="text" name="last_semester" id="last_semester"  placeholder="上学期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">下学期</label>
            <div class="layui-input-block">
                <input type="text" name="next_semester" id="next_semester"  placeholder="下学期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="insert">立即添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#year'
            ,type: 'year'
        });
        laydate.render({
            elem: '#last_semester'
            ,type: 'month'
            ,range: true
        });
        laydate.render({
            elem: '#next_semester'
            ,type: 'month'
            ,range: true
        });
    });
</script>
<script>
    $("#insert").click(function(){
        if(!$("#year").val()){
            layer.msg('学年不能为空',{icon:5,time:2000});
            return;
        }
        if(!$("#last_semester").val()){
            layer.msg('上学期不能为空',{icon:5,time:2000});
            return;
        }
        if(!$("#next_semester").val()){
            layer.msg('下学期不能为空',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/school_year/insert')}",
            data:$("#add").serialize(),
            type:'post',
            dataType:'json',
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        location.reload();
                    });
                }else{
                    layer.msg(res.msg,{icon:1,time:2000});
                }
            }
        });
    });
</script>
</html>